<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>添加管理员</title>
<{include file="js.html"}>
<script type="text/javascript">
	function getIndustry(spid,score) {
		 
		    var industryData = score;
            var is = document.getElementById(spid);
            var isv = is.options[is.selectedIndex].value;
			
            var ist = is.options[is.selectedIndex].text;
			
            is.options.length = 0;
            var count='';
			
            var pAs = industryData.split(",");
			
            for (var pA in pAs) {
                var pA_parts = pAs[pA].split("|");
                if (isv == "00") {
                	 if (ist == pA_parts[1]) {
                        count = is.options.length;
                     }
                }
                is.options.add(new Option(pA_parts[1], pA_parts[0]));
            }
 
            if (is.options.length == 0) {
               is.style.display = true;
                is.options.add(new Option("", "000000"));
            }
            else {
                is.disabled = false;
            }
			/*if(count!='')
		    {
				 is.options[count].selected = true;
				
			}*/
			
			
			 
           
        }
      function changeName(spid,snid,siid,name) {
		
            var is = document.getElementById(spid);
			
			  var sv = is.options[is.selectedIndex].value;
			
			   var cAs = name.split(",");
               for (var cA in cAs) {
               var cA_parts = cAs[cA].split("|");
                
                if ( sv == cA_parts[0]) {
                     var sn = document.getElementById(snid);
					 var si = document.getElementById(siid);
					 sn.value = cA_parts[1];
					 si.value =  cA_parts[0];
					
                }
            }
           
        }
	 function changeTrade(spid,snid,trade) {
		
            var is = document.getElementById(spid);
            var isv = is.options[is.selectedIndex].value;
            var ist = is.options[is.selectedIndex].text;
			 var sn = document.getElementById(snid);
            is.options.length = 0;
            var count='';
            var pAs = trade.split(",");
			pAs.pop();
            for (var pA in pAs) {
				
                var pA_parts = pAs[pA].split("|");
                	 if (ist == pA_parts[1]) {
                        count = is.options.length;
						
                }
                is.options.add(new Option(pA_parts[1], pA_parts[0]));
            }
			/*if(count=='')
			{
				 is.options[0].selected = true;
				 sn.value =  is.options[is.selectedIndex].value;
			}
			else
			{
				 is.options[count].selected = true;
				  sn.value =  is.options[is.selectedIndex].value;
			}*/
        }
		 function rechangeTrade(spid,snid,trade) {
            var is = document.getElementById(spid);
		    var sv = is.options[is.selectedIndex].value;
		    var sn = document.getElementById(snid);
			sn.value = sv;
			
        }
	
    function loadData(spid,snid,siid,score,name,suc)
	{
		
 
		getIndustry(spid,score);
		 changeName(spid,snid,siid,name);
		 $(".formTwo").Validform({
			  btnSubmit:".inp",
			  btnReset:".btn_reset",
			  ajaxPost:true,
			  beforeSubmit:function(curform){
				  saveCompanyInfo('<{$_basename}>?action=save','<{$row.id}>');
				  //alert('<{$_basename}>?action=save&id=<{$row.id}>');
			 	
				   document.getElementById("myFormOne").submit();
				   //alert('确定要上传？');
		return false;	
	},	
		 		
	});
	}    
    </script>
	<script type="text/javascript">
	function createAjax(){
			var xmlHttp = false;
			if (window.XMLHttpRequest){
				xmlHttp = new XMLHttpRequest();
			}else if(window.ActiveXObject){
				try{
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e){
					try{
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){
						xmlHttp = false;
					}
				}
			}
			return xmlHttp;	
	}
	var ajax = null;
	function getCity(provinceid){
		ajax = createAjax();
		//ajaxýnew XMLHTTPRequest;
		ajax.onreadystatechange=function(){
			if(ajax.readyState == 4){
				if(ajax.status == 200){	
                    var city=document.getElementById("city");				
					var cities = ajax.responseXML.getElementsByTagName("city");
					city.length = 0;
					var myoption = document.createElement("option");
					myoption.value = "";
					myoption.innerText = "--请选择市--";
					city.appendChild(myoption);
					for(var i=0;i<cities.length;i++){
						var city_id = cities[i].childNodes[0].childNodes[0].nodeValue;
						var city_name = cities[i].childNodes[1].childNodes[0].nodeValue;
						var myoption = document.createElement("option");
						myoption.value = city_id;
						myoption.innerText = city_name;
						city.appendChild(myoption);
					}
				}
			}
		}
 
		ajax.open("post","selectPro.php",true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("provinceid="+provinceid);
 
	}
 
	function getCounty(cityid){
		ajax = createAjax();
		ajax.onreadystatechange=function(){
			if(ajax.readyState == 4){
				if(ajax.status == 200){
                    var county=document.getElementById("county");				
					var cities = ajax.responseXML.getElementsByTagName("county");
					county.length = 0;
					var myoption = document.createElement("option");
					myoption.value = "";
					myoption.innerText = "--请选择县区--";
					county.appendChild(myoption);
					for(var i=0;i<cities.length;i++){
						var city_id = cities[i].childNodes[0].childNodes[0].nodeValue;
						var city_name = cities[i].childNodes[1].childNodes[0].nodeValue;
						var myoption = document.createElement("option");
						myoption.value = city_id;
						myoption.innerText = city_name;
						county.appendChild(myoption);
					}
				}
			}
		}
		ajax.open("post","selectPro.php",true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("cityid="+cityid);
	}
</script>

<script>
$(function() {
		$("#myFormOne").submit(function() {
			return queding('是否保存？', ".subChecks");
		})
		$("[name=first]").change(function(){
			var cid = $(this).val();
			var url = 'company_add.php?action=getCategory';
			if(cid){
				$.post(
					url,
					{cid:cid},
					function(data){
						if(data.error == '0'){
							$("[name=second]").html(data.html);
						}
					},'json'
					)
			}
		})
		})
</script>	
</head>
<body onload="loadData('selScore','score->name','score->id','<{$score}>','<{$name}>','<{$add_success}>'); changeTrade('selTrade','trade->id','<{$trade}>')">
<div class=" box pd-20" >
    <form  id="myFormOne"  method="post"  enctype='multipart/form-data' class="form formOne  form-horizontal"  >
    	<div class="row cl" >
			<label class="form-label col-3"><span class="c-red">*</span>公司名称:</label>
			<div class="formControls col-5" >
				<input type="text"class="input-text" value='<{$row.title}>' placeholder="请输入公司名" id="company-name" name="title" datatype="*" nullmsg="公司名不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
         <div class="row cl" >
			<label class="form-label col-3"><span class="c-red" >*</span>公司正面照片:</label>
			<div class="formControls col-5">
				<input placeholder="请上传图片" id="company-img" name="img" datatype="*" nullmsg="必须上传图片" type="file" <{if $row.img==''}> class="subCheck" <{/if}> name="img" id="img"  style="height:30px; margin-top:6px " />
			</div>
			<div class="col-4"> </div>
		</div>
     <{if $row.img!=""}>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>预览:</label>
			<div class="formControls col-5">
				<a target="_blank" href="../admin/upload/image/large/<{$row.img}>"><img src="../admin/upload/image/small/<{$row.img}>" width="110" height="60" /></a>
			</div>
			<div class="col-4"> </div>
		</div>
        <{/if}>
		<div class="row cl" >
			<label class="form-label col-3"><span class="c-red" >*</span>营业执照:</label>
			<div class="formControls col-5">
				<input  type="file" <{if $row.businesslicense==''}> class="subCheck" <{/if}> name="businesslicense" id="businesslicense"  style="height:30px; margin-top:6px " />
			</div>
			<div class="col-4"> </div>
		</div>
     <{if $row.businesslicense!=""}>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>预览:</label>
			<div class="formControls col-5">
				<a target="_blank" href="../admin/upload/test/large/<{$row.businesslicense}>"><img src="../admin/upload/test/small/<{$row.businesslicense}>" width="110" height="60" /></a>
			</div>
			<div class="col-4"> </div>
		</div>
        <{/if}>
		
		<div class="row cl" >
			<label class="form-label col-3"><span class="c-red" >*</span>法人照片:</label>
			<div class="formControls col-5">
				<input  type="file" <{if $row.legalperson==''}> class="subCheck" <{/if}> name="legalperson" id="legalperson"  style="height:30px; margin-top:6px " />
			</div>
			<div class="col-4"> </div>
		</div>
     <{if $row.legalperson!=""}>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>预览:</label>
			<div class="formControls col-5">
				<a target="_blank" href="../admin/upload/person/large/<{$row.legalperson}>"><img src="../admin/upload/person/small/<{$row.legalperson}>" width="110" height="60" /></a>
			</div>
			<div class="col-4"> </div>
		</div>
        <{/if}>

		<div class="row cl" >
			<label class="form-label col-3"><span class="c-red">*</span>公司评级星级:</label>
			<div class="formControls col-5" >
			<{if $row.star!=false}>
				<input type="text" class="input-text" value='<{$row.star}>' id="company-name" name="star"/>
				<{else}>
				<input type="text" class="input-text" value='暂无' id="company-name" name="star"/>
			<{/if}>
			</div>
			<div class="col-4"> </div>
		</div>
     <div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>所属行业:</label>
			<div class="formControls col-5">
			<{if $row.id}>
			    <select  name="first" class="subChecks">
                 <{foreach item=lists from=$ress}>	
				  <option <{if $lists.title==$cate_1.title}>selected<{/if}> value="<{$lists.id}>">
				  <{$lists.title}>
				  </option>  
				 <{/foreach}>
				</select>  
				<select name="second" class="subChecks">  
				  <option value=""><{$cate_2.title}></option>  
				</select>  
				<{else}>
				<select  name="first" class="subChecks">
                 <{foreach item=lists from=$ress}>				
				  <option value="<{$lists.id}>"><{$lists.title}></option>  
				 <{/foreach}>
				</select>  
				<select name="second" class="subChecks">  
				  <option value="">--请选择--</option>  
				</select> 
               <{/if}>				
				</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl" style="display:none;">
			<label class="form-label col-3"><span class="c-red">*</span>公司评级分数:</label>
			<div class="formControls col-5">
            <select class="subCheck" name="sore" id="selScore"  style=" border-radius:0px; -webkit-appearance:none; -webkit-border-radius:0px; width:180px; height:29px; background-color:transparent; border-color:#CCC" datatype="*" nullmsg="公司名不能为空" onchange=" changeName('selScore','score->name','score->id','<{$name}>')"><option  value= "00"><{$row.score}></option></select>
			</div>
			<div class="col-4"> </div>
		</div>
        <div class="row cl" style="display:none;">
			<label class="form-label col-3"><span class="c-red">*</span> 公司评级名称:</label>
			<div class="formControls col-5">
				<input type="text" id="score->name" readonly="readonly" placeholder="选择评级分数自动生成" autocomplete="off" value="" class="input-text" datatype="*" nullmsg="评级名称不能为空">
                <input type="text" id="score->id" style="display:none" value="" >
			</div>
			<div class="col-4"> </div>
		</div>
      <div class="row cl" style="display:none;">
			<label class="form-label col-3"><span class="c-red">*</span>公司行业:</label>
			<div class="formControls col-5">
            <select class="subCheck" name="sore" id="selTrade"  onchange="rechangeTrad('selTrade','trade->id','<{$trade}>')" style=" border-radius:0px; -webkit-appearance:none; -webkit-border-radius:0px; width:180px; height:29px; background-color:transparent; border-color:#CCC"  datatype="*" nullmsg="公司名不能为空"><option  value= "00"><{$trades}></option></select>
              <input type="text" id="trade->id" style="display:none" value="" >
			</div>
			<div class="col-4"> </div>
		</div>
       
	   <div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>地址:</label>
			<div class="formControls col-5">
			
				<select name="province" id="province" onchange="getCity(this.value)">
				<{if $row.province==false}>
				<option value="">--请选择省--</option>
				<{else}>
				<option value="<{$row.province}>"><{$row.province}></option>
				<{/if}>
				<{foreach item=res from=$result}>
				<option name="sheng" value="<{$res.provinceid}>"><{$res.province}></option> 
				<{/foreach}>
				</select>
				<select name="city" id="city" onChange="getCounty(this.value)">
				<{if $row.cirty==false}>
				 <option name="shi" value="">--请选择市--</option>
				 <{else}>
				 <option name="shi" value="<{$row.cirty}>"><{$row.cirty}></option>
				 <{/if}>
				</select>
				<select name="county" id="county">
				<{if $row.county==false}>
				 <option name="xian" value="">--请选择县区--</option>
				<{else}>
				 <option name="shi" value="<{$row.county}>"><{$row.county}></option>
				<{/if}>
				</select>
			</div>
			<div class="col-4"> </div>
		</div>
		
	
		<{foreach item=content from=$list}>
        <{if  $content.import==0}>
        <div class="row cl">
			<label class="form-label col-3" ><span class="c-red"></span><{$content.title}>：</label>
			<div class="formControls col-5">
			<{if $content.title eq "摘要"}>
				<textarea type="text"    name ="content[]"  id="<{$content.id}>_<{$content.cd_id}>" style="height:100px"  placeholder="内容" autocomplete="on" value="<{$content.content}>" class="input-text" datatype="*" nullmsg="<{$content.content}>不能为空"><{$content.content}></textarea>
			<{else}>
				<input type="text"    name ="content[]"  id="<{$content.id}>_<{$content.cd_id}>"   placeholder="内容" autocomplete="on" value="<{$content.content}>" class="input-text" datatype="*" nullmsg="<{$content.content}>不能为空">
			<{/if}>
				<input type="text"  style="display:none"  name ="content_id[]"  id="<{$content.id}>_<{$content.cd_id}>"   placeholder="内容" autocomplete="off" value="<{$content.id}>" class="input-text">
			</div>
			<div class="col-4"> </div>
		</div>
        <{/if}>
	    <{/foreach}>
		<div class="row cl">
			<div class="col-9 col-offset-3">
            <input  type="submit" name="save"  value="保存" class="inp" />
            <input  type="button" name="btn_reset"  value="重置" class="btn_reset inp" />
			</div>
		</div>
    </form>  
</div>
<script type="text/javascript">
 function saveCompanyInfo(url,c_id)
 {
	 
	    var si = document.getElementById('score->id');
		var ti = document.getElementById('trade->id');
		var title = $('#company-name').val();
		var level_id=si.value;
		var trade_id=ti.value;
    	 $.post(
			url,
			{ datatype:'company_name',title:title,level_id:level_id,trade_id:trade_id,c_id:c_id},
			
			function(data){
				var data_arr = data.split(",");
				for (var sub_key in data_arr) {
                var sub_arr = data_arr[sub_key].split("|");
                var new_id;
			    var succ;
                if (sub_arr[0] == "01") {
                	 new_id = sub_arr[1];
                }
                if (sub_arr[0] == "02") {
                	 succ = sub_arr[1];
                }
            }
				
				if(succ=='1'){
					saveContent(url,new_id);
				}
			}
		)
 }
 function saveContent(url,c_id)
 {
	   var succ;
	   var len =  $("[name=content_content]").length;
	   var i=0;
	   //alert(len);
	 $("[name=content_content]").each(function(index){   
	  var self = $(this);
	  var content = self.val();
	  var id_str = self.prop('id');
	  var id_arr = id_str.split('_');
	  var cdt_id = id_arr[0]; 
	  var cd_id = id_arr[1];
	  $.post(
			url,
			{datatype:'company_content',content:content,c_id:c_id,cdt_id:cdt_id,cd_id:cd_id},
			function(data){
				i++;
				if(data=='1'){
					if(i==len)
					{
						add_success(1);	
						
					}
				}
				else
				{
					add_success(0);	
					return false;
				}
				
			}
		)
	
	});
	
 }
 
 function  add_success(suc){
	if(suc==1)
	{
		layer.msg('保存成功', {icon: 1});
				
	}
	if(suc==0)
	{
		
		layer.msg('保存失败', {icon:5,time:1000});
	
		
	}
	
   }
</script>
</body>
</html>